﻿using System;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace abp
{
    public class MyTestService:ApplicationService,ITestService
    {
        public readonly IRepository<MyTest,int> _myTestRepository;

        public MyTestService(IRepository<MyTest,int> myTestRepository)
        {
            _myTestRepository = myTestRepository;
        }

        public async Task<List<MyTestDto>> GetListAsync()
        {
            var entityList = await _myTestRepository.GetListAsync();

            return ObjectMapper.Map<List<MyTest>,List<MyTestDto>>(entityList);
        }

        public async Task<MyTestDto> GetAsync(int id)
        {
            var entity = await _myTestRepository.GetAsync(t => t.Id == id);
            //var query = _myTestRepository.GetAsync(id);


            return ObjectMapper.Map<MyTest, MyTestDto>(entity);
        }

        public async Task<MyTestDto> CreateAsync(MyTestDto input)
        {
            var model = ObjectMapper.Map<MyTestDto,MyTest>(input);

            MyTest entity =await _myTestRepository.InsertAsync(model);

            return ObjectMapper.Map<MyTest, MyTestDto>(entity);
        }

        public async Task<MyTestDto> UpdateAsync(MyTestDto input)
        {
            var model = ObjectMapper.Map<MyTestDto, MyTest>(input);

            MyTest entity = await _myTestRepository.UpdateAsync(model);

            return ObjectMapper.Map<MyTest, MyTestDto>(entity);
        }
    }
}